﻿using System;
using System.Collections.Generic;
using System.Text;
using TarreOA.TarreOAModels;
using TarreOA.TarreOADAL;

namespace TarreOA.TarreOABLL
{
    public class UserFileCabinettbService
    {
        /// <summary>
        /// 保存个人文件柜记录信息
        /// </summary>
        /// <param name="fileTitle"></param>
        /// <param name="fileContent"></param>
        /// <param name="FilePath"></param>
        /// <param name="FileUploadTime"></param>
        /// <param name="UserLoginName"></param>
        /// <returns></returns>
        public int saveUserFileCabinetInfo(string fileTitle, string fileContent, string filePath, DateTime fileUploadTime, string userLoginName)
        {
            UserFileCabinettbDAO userFileCabinettbDAO = new UserFileCabinettbDAO();
            return userFileCabinettbDAO.saveFileCabinetFile(fileTitle, fileContent, filePath, fileUploadTime, userLoginName);
        }

        /// <summary>
        /// 根据用户登录名查找个人文件柜记录信息
        /// </summary>
        /// <param name="UserLoginName"></param>
        /// <returns></returns>
        public List<UserFileCabinettb> findByUserLoginName(string userLoginName)
        {
            UserFileCabinettbDAO userFileCabinettbDAO = new UserFileCabinettbDAO();
            return userFileCabinettbDAO.findByUserLoginName(userLoginName);
        }

        /// <summary>
        /// 根据文件编号查找记录信息
        /// </summary>
        /// <param name="fid"></param>
        /// <returns></returns>
        public UserFileCabinettb findByFileId(int fid)
        {
            UserFileCabinettbDAO userFileCabinettbDAO = new UserFileCabinettbDAO();
            return userFileCabinettbDAO.findByFileId(fid);
        }

        /// <summary>
        /// 根据记录编号删除记录信息
        /// </summary>
        /// <param name="fids"></param>
        /// <returns></returns>
        public bool delFileCabinetInfoByFileId(string[] fids)
        {
            if (fids != null && fids.Length > 0)
            {
                int count = 0;
                UserFileCabinettbDAO userFileCabinettbDAO = new UserFileCabinettbDAO();
                for (int i = 0; i < fids.Length; i++)
                {
                    count++;
                    userFileCabinettbDAO.delFileCabinetInfoByFileId(int.Parse(fids[i]));
                }
                if (count == fids.Length)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 根据文件路径和当前用户登录名查找文件信息
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="UserLoginName"></param>
        /// <returns></returns>
        public List<UserFileCabinettb> findByFilePathAndUserLoginName(string filePath, string userLoginName)
        {
            UserFileCabinettbDAO userFileCabinettbDAO = new UserFileCabinettbDAO();
            return userFileCabinettbDAO.findByFilePathAndUserLoginName(filePath, userLoginName);
        }
    }
}
